package com.alipear.shopcredit.common.view.wrapper;

import android.graphics.Bitmap;
import android.net.Uri;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.alipear.ppwhere.common.R;


/**
 * Created by zoulinlin on 2015/3/27.
 */
public class ListCellViewWrapper extends  ViewWrapperCommon{
    /*Wrapper R.layout.listview_cell_view*/
    private ImageView mCellImageView;
    private TextView mCellTitleView;
    private TextView mCellInfoView;
    private FrameLayout mCellRightView;
    private View mRightArrow;



    public  ListCellViewWrapper(View rootView) {
        super(rootView);
        mCellImageView = (ImageView)rootView.findViewById(R.id.cell_icon);
        mCellTitleView = (TextView)rootView.findViewById(R.id.cell_title);
        mCellInfoView = (TextView)rootView.findViewById(R.id.cell_info);
        mCellRightView = (FrameLayout)rootView.findViewById(R.id.cell_right_view);
        mRightArrow = rootView.findViewById(R.id.right_arrow);
        mCellImageView.setVisibility(View.GONE);
        mCellRightView.setVisibility(View.GONE);
    }

    public ListCellViewWrapper setTitle(int title) {
        mCellTitleView.setText(title);
        return this;
    }

    public ListCellViewWrapper setTitle(String title) {
        mCellTitleView.setText(title);
        return this;
    }

    public ListCellViewWrapper setInfo(String info) {
        mCellInfoView.setText(info);
        return this;
    }

    public ListCellViewWrapper setImageURI(Uri imageURI) {
        mCellImageView.setImageURI(imageURI);
        mCellImageView.setVisibility(imageURI == null ? View.GONE: View.VISIBLE);
        return this;
    }

    public ListCellViewWrapper setImageResource(int resId) {
        mCellImageView.setImageResource(resId);
        mCellImageView.setVisibility(View.VISIBLE);
        return this;
    }

    public ListCellViewWrapper setImage(Bitmap bm) {
        mCellImageView.setImageBitmap(bm);
        mCellImageView.setVisibility(bm == null ? View.GONE: View.VISIBLE);
        return this;
    }

    public ListCellViewWrapper setRightView(View rightView) {
        mCellRightView.removeAllViews();
        if (rightView != null) {
            mCellRightView.addView(rightView);
        }
        mCellRightView.setVisibility(View.VISIBLE);
        return this;
    }

    public ListCellViewWrapper setOnClickListener(View.OnClickListener listner) {
        getRootView().setOnClickListener(listner);
        return this;
    }

    public ListCellViewWrapper setRightArrowEnabled(boolean flag) {
        if (mRightArrow != null) {
            mRightArrow.setVisibility(flag ? View.VISIBLE: View.INVISIBLE);
        }
        return this;
    }
}
